#pragma once
#include "object_factory.h"
#include "scanner.h"
#include <istream>
#include <boost/ptr_container/ptr_list.hpp>

namespace Pdf
{
    class Parser : public Scanner<Parser>
    {
    public:
                                        Parser(std::istream *stream);
                                       ~Parser();

        Object::Ptr                     read();
        void                            skipEOL();

        template <typename TargetType>
        typename TargetType::Ptr        read();

	private:
        typedef std::list<ObjectFactory*> FactoryStack;
        friend struct Scanner<Parser>;

        void                            onCharacter(char c);
        void                            onEnterWhiteSpace();
        void                            onLeaveWhiteSpace();
        void                            onEnterEOL();
        void                            onLeaveEOL();
        void                            onEnterComment();
        void                            onLeaveComment();
        void                            onEnterString();
        void                            onLeaveString();
        void                            onEnterDictionary();
        void                            onLeaveDictionary();
        void                            onEnterName();
        void                            onLeaveName();
        void                            onEnterArray();
        void                            onLeaveArray();
        void                            onEnterNames();
        void                            onLeaveNames();
        void                            onEnterToken();
        void                            onLeaveToken();

        void                            push(ObjectFactory *factory);
        void                            pop();

        std::streambuf*                 streambuf;
        Object::Ptr                     object;
        FactoryStack                    factories;
    };
}

#include "parser.inl"